﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SalesSys.DAL;

namespace SalesSys.BLL
{
   public class ReportBLL
    {
          object[][] GetTableView(string sql, bool isHander = true)
        {

            var rep = RepositoryFactory.GetRepositoryByFactoryUnit<IDepotHistroyRep>();
            var dt = rep.GetTableInfo(sql);
            var list = new List<object[]>();
            if (isHander)
            {
                var cols = dt.Columns.Cast<DataColumn>().Select(p => (object)p.ColumnName).ToArray();
                list.Add(cols);
            }

            var data = dt.Rows.Cast<DataRow>().Select(p => p.ItemArray).ToArray();
            list.AddRange(data);
            return list.ToArray();
        }

          public object[][] GetDepotInfo(bool isHander = true)
          {
              return GetTableView("select * from [NowDepotInfo] order by 仓库,商品,性能,规格", isHander);
          }
          public object[][] GetDayOrderList(bool isHander , string deptNames,DateTime? settlementTime)
          {
              string sql = "select * from [DayOrder] where 1=1 ";
              if (settlementTime.HasValue)
              {
                  sql += " and 结算日期>= '" + settlementTime.Value.Date.ToString("yyyy-MM-dd") + "' and 结算日期 <='" + settlementTime.Value.Date.AddDays(1).ToString("yyyy-MM-dd") + "'";
              }
              if (!string.IsNullOrEmpty(deptNames))
              {
                  sql += " and 事业部 in ("+deptNames+")";
              }
              sql += " order by 结算日期 desc ";
              return GetTableView(sql, isHander);
          }

     
    }
}
